package com.cvit.cn.controller;

import java.text.ParseException;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cvit.cn.bean.Manager;
import com.cvit.cn.bean.Msg;
import com.cvit.cn.service.ManagerService;

@Controller
public class ManagerController {
	@Autowired
	ManagerService managerService;
	
	
	/**
	 * 新增管理员账号密码
	 * **/
	@RequestMapping("/addManager")
	@ResponseBody
	public Msg addManager(Manager manager){
		managerService.addManager(manager);
		return Msg.success();
	}
	/**
	 * 新增供应商账号密码
	 * **/
	@RequestMapping("/addSupplier")
	@ResponseBody
	public Msg addSupplier(Manager manager){
		managerService.addSupplier(manager);
		return Msg.success();
		
	}
	/**
	 * 查询供应商账号和密码
	 * */
	@RequestMapping("/seleSupplier")
	@ResponseBody
	public Msg seleManager(@RequestParam("name")String name,@RequestParam("password")String password,@RequestParam("role")String role){
		Manager m=managerService.seleManager(name,password,role);
		if(m==null){
			return Msg.fail().add("F", "账号或者密码错误");
		}
		return Msg.success().add("m", m);
		
	}
	/**
	 * 查询管理员账号和密码
	 * */
	@RequestMapping("/seleManager")
	@ResponseBody
	public Msg seleSupplier(@RequestParam("id")String id,@RequestParam("password")String password,@RequestParam("role")String role){
		Manager m=managerService.seleSupplier(id,password,role);
		if(m==null){
			return Msg.fail().add("F", "账号或者密码错误");
		}
		return Msg.success().add("m", m);
		
	}
	/**
	 * 供应商修改密码
	 * */
	@RequestMapping("/updataSupplier")
	@ResponseBody
	public Msg updataSupplier(@RequestParam("id")String id,@RequestParam("name")String name,@RequestParam("password")String password,@RequestParam("role")String role){
		Manager manager=new Manager();
		manager.setId(id);
		manager.setName(name);
		manager.setPassword(password);
		manager.setRole(role);
		managerService.updataManager(manager);
		return Msg.success();
	}
	/**
	 * 管理员修改密码
	 * */
	@RequestMapping("/updataManager")
	@ResponseBody
	public Msg updataManager(@RequestParam("id")String id,@RequestParam("password")String password,@RequestParam("role")String role){
		Manager manager=new Manager();
		manager.setId(id);
		manager.setPassword(password);
		manager.setRole(role);
		managerService.updataManager(manager);
		return Msg.success();
	}
	/**
	 * 根据id删除
	 * */
	@RequestMapping("/deleManagerId")
	@ResponseBody
	public Msg deleManager(@RequestParam("id")String id){
		managerService.deleManagerId(id);
		return Msg.success();
	}
	

}
